{block name="main"}
		<!-- page -->
        <form class="v-filter-container">
            <div class="filter-fields-wrap">
                <div class="filter-item clearfix">
                    <div class="filter-item__field">
                        <div class="v__control-group">
                            <label class="v__control-label">队长名称</label>
                            <div class="v__controls">
                                <input type="text" id="search_text" class="v__control_input" placeholder="队长用户名/昵称" autocomplete="off">
                            </div>
                        </div>
                        <div class="v__control-group">
                            <label class="v__control-label">手机号</label>
                            <div class="v__controls">
                                <input type="text" id="iphone" class="v__control_input" autocomplete="off" placeholder="手机号">
                            </div>
                        </div>

                        <div class="v__control-group">
                            <label class="v__control-label">队长等级 </label>
                            <div class="v__controls">
                                <select class="v__control_input" id="level" >
                                    <option value="">请选择等级...</option>
                                    {foreach name="agent_level" item="value"}
                                    <option value="{$value.id}">{$value.level_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="filter-item clearfix">
                    <div class="filter-item__field">
                        <div class="v__control-group">
                            <label class="v__control-label"></label>
                            <div class="v__controls">
                                <a class="btn btn-primary search" id="search"><i class="icon icon-search"></i> 搜索</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>

		<div class="screen-title">
			<span class="text">信息列表</span>
		</div>
	<ul class="nav nav-tabs v-nav-tabs" role="tablist">
		<li role="presentation" class="active"><a href="#all" aria-controls="all"  data-type="all" role="tab" data-toggle="tab" class="flex-auto-center alluser" data-id="5">全部<br><span class="all_count"></span></a></li>
		<li role="presentation"><a href="#audited" aria-controls="audited"  data-type="audited" role="tab" data-toggle="tab" class="flex-auto-center audited" data-id="2">已审核<br><span class="audited_count"></span></a></li>
		<li role="presentation"><a href="#pending" aria-controls="pending" data-type="pending" role="tab" data-toggle="tab" class="flex-auto-center pending" data-id="1">待审核<span class="pending_count"></span></a></li>
		<li role="presentation"><a href="#refused" aria-controls="refused" data-type="refused" role="tab" data-toggle="tab" class="flex-auto-center refused" data-id="-1">已拒绝<span class="refused_count"></span></a></li>
	</ul>
		<table class="table v-table table-auto-center">
			<thead>
			<tr>
				<th>推荐人</th>
				<th>队长</th>
				<th>手机</th>
				<th>队长等级</th>
				<th>累积分红/已发放分红</th>
				<th>状态</th>
				<th class="col-md-2 pr-14 operationLeft">操作</th>
			</tr>
			</thead>
			<tbody id="list">




			</tbody>
		</table>
		<input type="hidden" id="page_index" value="">
		<nav aria-label="Page navigation" class="clearfix">
			<ul id="page" class="pagination pull-right"></ul>
		</nav>
<input type="hidden" id="merchant_status" value="{$merchant_status}">
<input type="hidden" id="merchant_expire" value="{$merchant_expire}">
		<!-- page end -->
{/block}
{block name="script"}
<script>
    require(['util'],function(util){
        util.initPage(getList(1,5));
        function getList(page_index,status){
            $("#page_index").val(page_index);
            var merchant_status= $("#merchant_status").val();
            var merchant_expire= $("#merchant_expire").val();
            var level = $("#level").val();
            var search_text = $("#search_text").val();
            var iphone = $("#iphone").val();
            $.ajax({
                type : "post",
                url : '{$teamAgentListUrl}',
                async : true,
                data : {
                    "page_index" :page_index, "search_text" : search_text, "level_id" : level, "is_team_agent" : status,"iphone":iphone
                },
                success : function(data) {
                    if(data['page_count']>=3){
                        if(merchant_status==1){
                            var html = '';
                            html += '<div style="min-height: 100px;font-size: 16px;padding-top: 30px">免费版本数据量已达上限，需要继续使用请联系客服电话<span class="text-primary">400-889-6625</span>或<a href="http://q.url.cn/s/EPvXzVm" target="_blank" class="text-primary"><i class="icon-sale icon"></i>  QQ客服</a>！</div>';
                            util.confirm3('',html);
                        }
                    }
                    var html = '';
                    if (data["data"].length>0) {
                        for (var i = 0; i < data["data"].length; i++) {
                            html += '<tr>';
                            if(data['data'][i]["referee_id"]==null || data['data'][i]["referee_id"]==0){
                                html += '<td>总店</td>';
                            }else{
                                html += '<td><img src="' + __IMG(data['data'][i]["referee_headimg"]) + '" width="30" height="30">';
                                html += '<span class="block mt-04">' + data['data'][i]["referee_name"] + '</span></td>';
                            }
                            html += '<td><img src="' + __IMG(data['data'][i]["user_headimg"]) + '" width="30" height="30">';
                            html += '<span class="block mt-04">' + data['data'][i]["user_name"] + '</span></td>';
                            html += '<td>';
                            html += '<span class="block">' + data['data'][i]["mobile"] + '</span></td>';
                            html += '<td ><span class="block">' +data["data"][i]["level_name"] +'</span></td>';
                            if(data["data"][i]['account']){
                                html += '<td><p class="p">';
                                html += '<span class="label label-success">累积：'+ data["data"][i]['account']["total_bonus"] +'元</span>';
                                html += '</p>';
                                html += '<span class="label label-danger">已发放：'+ data["data"][i]['account']["grant_bonus"] +'元</span></td>';
                            }else{
                                html += '<td><p class="p">';
                                html += '<span class="label label-success">累积：0.00元</span>';
                                html += '</p>';
                                html += '<span class="label label-danger">已发放：0.00元</span></td>';
                            }

                            if(data["data"][i]['is_team_agent'] == 2){
                                html += '<td><a href="javascript:;" class="label label-success">已审核</a></td>';
                                if(merchant_expire==1){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else if(merchant_status==1 && data['page_count']>=3){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else{
                                    html += '<td class="fs-0 operationLeft"><a class="btn-operation" href="'+__URL('ADDONS_MAINteamAgentInfo&agent_id='+ data['data'][i]['uid']) +'">详情</a>';
                                    html += '<a class="btn-operation" href="'+__URL('ADDONS_MAINteamAgentOrderList&agent_id='+ data['data'][i]['uid']) +'">订单</a>';
                                    html += '<a class="btn-operation" href="' +__URL('ADDONS_MAINlowerAgentList&distributor_id='+ data['data'][i]['uid']) +'">下级分销商</a>';
                                    html += '<a class="btn-operation del" href="javascript:;" data-id="'+ data['data'][i]['uid']+'">移除</a>';
                                    html += '</td>';
                                }

                            }else if(data["data"][i]['is_team_agent'] == 1){
                                html += '<td><a href="javascript:;" class="label label-danger">待审核</a></td>';
                                if(merchant_expire==1){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else if(merchant_status==1 && data['page_count']>=3){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else{
                                    html += '<td class="fs-0 operationLeft"><a href="javascript:;" class="btn-operation isexamine save" data-type=2 data-id="'+ data["data"][i]['uid']+'">通过</a><a href="javascript:void(0);" class="btn-operation isexamine save" data-type=-1 data-id="'+ data["data"][i]['uid']+'">拒绝</a></td>';
                                }
                            }else if(data["data"][i]['is_team_agent'] == -1){
                                html += '<td ><a href="javascript:;" class="label label-danger">审核不通过</a></td>';
                                if(merchant_expire==1){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else if(merchant_status==1 && data['page_count']>=3){
                                    html += '<td><a href="javascript:;">无权操作</a></td>';
                                }else{
                                    html += '<td class="fs-0 operationLeft"><a href="javascript:;" class="btn-operation isexamine save" data-type=2 data-id="'+ data["data"][i]['uid']+'">重新审核</a><a href="javascript:;" class="btn-operation del text-red1" data-id="' + data['data'][i]['uid'] +'">删除</a></td>';
                                }
                            }
                            html += '</tr>';
                        }
                    } else {
                        html += '<tr><td class="h-200" colspan="7">暂无符合条件的数据记录</td></tr>';
                    }
                    $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                    $('.all_count').html('('+data['count']+')');
                    $('.audited_count').html('('+data['count1']+')');
                    $('.pending_count').html('('+data['count2']+')');
                    $('.refused_count').html('('+data['count3']+')');
                    $("#list").html(html);
                }
            });
        }
        $('.search').on('click',function(){
            util.initPage(getList(1,5));
        });
        $('.alluser').on('click',function(){
            util.initPage(getList(1,5));
        });
        $('.audited').on('click',function(){
            util.initPage(getList(1,2));
        });
        $('.pending').on('click',function(){
            util.initPage(getList(1,1));
        });
        $('.refused').on('click',function(){
            util.initPage(getList(1,-1));
        });
        $('body').on('click','.del',function(){
            var uid = $(this).data('id');
            util.alert('是否移除队长？',function(){
                $.ajax({
                    type : "post",
                    url : "{$delTeamAgentUrl}",
                    data:{'uid':uid},
                    async : true,
                    success : function(data) {
                        if(data["code"] > 0 ){
                            util.message(data["message"], 'success', getList($("#page_index").val(),5));
                        }else{
                            util.message(data["message"], 'danger');
                        }
                    }
                });
            })
        })
        $('body').on('click','.save',function(){
            var status = $(this).data('type');
            var uid = $(this).data('id');
            if(status==-1){
                util.alert('确定审核不通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$setTeamAgentStatusUrl}",
                        data:{'uid':uid,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val(),5));
                            }else{
                                util.message(data["message"], 'danger');
                            }
                        }
                    });
                })
            }else{
                util.alert('确定审核通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$setTeamAgentStatusUrl}",
                        data:{'uid':uid,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val(),5));
                            }else{
                                util.message(data["message"], 'danger');
                            }
                        }
                    });
                })
            }
        })
    })
</script>
{/block}
